<template>
	<view class="container">
		<TopBtn v-if="type==1" :title="'我的预约'"></TopBtn>
		<TopBtn v-if="type==2" :title="'今日预约'"></TopBtn>
		<view class="nav" v-if="type==1">
			<view :class="{'act':request.status==0}" @click="navChange(0)">
				待确认
			</view>
			<view :class="{'act':request.status==1}" @click="navChange(1)">
				待就诊
			</view>
			<view :class="{'act':request.status==2}" @click="navChange(2)">
				已失效
			</view>
			<view :class="{'act':request.status==3}" @click="navChange(3)">
				已回绝
			</view>
		</view>
		<view :class="  type==1?'listBox mt60':'listBox'  ">
			<view class="list" v-for="n in list" :key="n.id">
				<view class="" @click="goinfo(n.id)">
					<view class="title flex-center">
						<image :src="n.patientAvatar" mode=""></image>
						<view class="">
							<view class="name">
								{{n.patientName}} <text>{{n.patientAge}}岁</text> <text>{{n.patientSex==1?'男':'女'}}</text>
							</view>
						</view>
					</view>
					<view class="typeBox">
						<view class="flex-center mb_17">
							<view>
								预约时间：
							</view>
							<uni-dateformat :date="n.appointTime" format="yyyy-MM-dd"></uni-dateformat>
							<view v-if="n.status==1" class="state flex-center-center">{{n.flag}}</view>
						</view>
						<view class="flex-center b_B_e">
							<view>
								预约机构：
							</view>
							{{n.hospitalName}} <text class="dengji">{{n.hospitalLevelName}}</text>
							<text class="HospitalType">{{n.hospitalTypeName}}</text>
						</view>
					</view>
					<view class="btmBox flex-sp-center">
						<uni-dateformat :date="n.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat>
						<view class="flex-center">
							查看详情
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getMyAppoint,
		getTodayAppoint
	} from '@/api/ConsultationRoom'
	export default {
		data() {
			return {
				act: "1",
				type: "",
				list: [],
				request: {
					pageNo: 1,
					pageSize: 10,
					// status: 0
				},
				maxNum: "",
			};
		},
		onLoad(options) {
			if (options.type) {
				this.type = options.type
				// this.getMyAppoint()
			}
			if (options.type == 1) {
				this.navChange(0)
			}
		},
		onReachBottom() {
			if (this.maxNum <= this.request.pageNo) return
			this.request.pageNo = this.request.pageNo + 1
			this.getMyAppoint()
		},
		methods: {
			goinfo(e) {
				uni.navigateTo({
					url: `/pages/ConsultationRoom/details/details?type=1&id=${e}`,
				})
			},
			navChange(e) {
				this.request.status = e
				// this.request.consultationMethod = ""
				this.request.pageNo = 1
				this.list = []
				this.getMyAppoint()
			},
			getMyAppoint() {
				if (this.type == 1) {
					getMyAppoint(this.request).then(res => {
						this.list.push(...res.data.list)
						let num = res.data.total / this.request.pageSize
						if (num.toString().includes('.')) {
							num = Math.ceil(num)
						}
						this.maxNum = num
					})
				}
				if (this.type == 2) {
					getTodayAppoint(this.request).then(res => {
						this.list.push(...res.data.list)
						let num = res.data.total / this.request.pageSize
						if (num.toString().includes('.')) {
							num = Math.ceil(num)
						}
						this.maxNum = num
					})
				}

			},
		}
	}
</script>

<style lang="less" scoped>
	.nav {
		width: 100%;
		background-color: #fff;
		font-size: 32rpx;
		color: rgba(51, 51, 51, 0.5);
		line-height: 28rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 60rpx;
		position: fixed;
		z-index: 9;
		top: 128rpx;

		view {
			flex: 1;
			text-align: center;
		}

		.act {
			color: #333333;
			font-weight: bold;
		}
	}

	.state {
		width: 86rpx;
		height: 33rpx;
		border-radius: 10rpx;
		border: 1px solid #3E6EFE;
		font-weight: 500;
		font-size: 22rpx;
		margin-left: 15rpx;
		color: #3E6EFE !important;
	}

	.b_B_e {
		padding-bottom: 20rpx;
		border-bottom: 1px solid #EEEEEE;
	}


	.listBox {
		margin-top: 43rpx;
		padding: 0 30rpx;

		.list {
			width: 690rpx;
			min-height: 182rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-bottom: 30rpx;

			&>view {
				width: 100%;
			}

			.btmBox {
				margin-top: 25rpx;
				font-weight: 500;
				font-size: 26rpx;
				color: #999999;
			}

			.title {
				.name {
					font-weight: bold;
					font-size: 32rpx;
					color: #333333;

					text {
						font-weight: 500;
						font-size: 26rpx;
						color: #333;
						margin-left: 19rpx;
					}
				}

				image {
					width: 58rpx;
					height: 58rpx;
					margin-right: 30rpx;
					border-radius: 50%;
				}
			}
		}

		.typeBox {
			margin-top: 15rpx;
			font-weight: 500;
			font-size: 28rpx;

			&>view {
				color: #333;

				&>view {
					color: #999;
				}
			}

			.dengji {
				display: inline-block;
				min-width: 63rpx;
				height: 33rpx;
				background: #DEF7ED;
				border-radius: 10rpx;
				font-weight: 500;
				font-size: 22rpx;
				color: #23CC88;
				text-align: center;
				line-height: 33rpx;
				margin: 0 10rpx;

			}

			.HospitalType {
				display: inline-block;
				min-width: 63rpx;
				height: 33rpx;
				background: #FDF3E1;
				border-radius: 10rpx;
				font-weight: 500;
				font-size: 22rpx;
				color: #F1AE34;
				text-align: center;
				padding: 0 8rpx;
				line-height: 33rpx;
				margin: 0 10rpx;
			}
		}
	}

	.mt60 {
		margin-top: 80rpx;
	}
</style>